package javaCode;

import javax.print.attribute.standard.NumberUp;

public class LeetCode563 {
	int value = 0;
	   public int findTilt(TreeNode root) {
		   value = 0;
		   backTrace(root);
		  return value;
	    }
	   public int  backTrace(TreeNode root) {
		  if(root == null){
			  return 0;
		  }
		  int leftSum = backTrace(root.left);
		  int rightSum = backTrace(root.right);
		  value += Math.abs(leftSum-rightSum);
		  return root.val+leftSum+rightSum;
	}
}
